package org.msn.mapper.database;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

public class DatabaseLinkPool<T> {
    private Map<String, List<T>> linkInfos = new ConcurrentHashMap<>();
    private final Random random = new Random();

    public void addLink(String type, T obj) {
        if (linkInfos.get(type) == null) {
            linkInfos.put(type, new ArrayList<>());
        }

        linkInfos.get(type).add(obj);
    }

    public T getLink(String type) {
        return linkInfos.get(type).get(random.nextInt(linkInfos.get(type).size()));
    }
}
